#pragma once


#include "qtabcontainer.h"



namespace micro
{
namespace gui
{


class QXTabContainer :	public QControl
{
protected:
    int				m_currentTab;
    int				m_style;


    bool            m_bDrag;
    int             m_dragItem;
    QPoint			m_dragPoint;


    bool			m_closeActive;
    int             m_closeItem;

    ///colors
    QCOLOR			m_bkColor;


    //QSize			m_sizeImag;
    QFont			m_font;//header font
    QPen			m_pen;

    QObArray<QTab>	m_tabList;

public:
    QXTabContainer( void );
    virtual ~QXTabContainer( void );
    virtual bool Create( QWindow * parent, int id = 0, UINT style = 0 );


protected:
    //virtual void OnPreRegisterClass(WNDCLASS& wcex);
    virtual bool OnPreCreate( CREATESTRUCT & cs );

    virtual bool OnSize( int type, int cx, int cy );
    virtual bool OnEraseBackground( QGraphics * );
    virtual bool OnPaint( QGraphics * pdc );
    //virtual bool OnNcPaint(QWindowGraphics & );
    virtual bool OnSetFocus( HWND hwnd );

    virtual bool OnLButtonDown( UINT flags, QPoint & point );
    virtual bool OnLButtonUp( UINT flags, QPoint & point );
    virtual bool OnLButtonDblClk( UINT flags, QPoint & point );
    //virtual bool OnRButtonDown(UINT flags, QPoint& point);


    virtual bool OnMouseLeave();
    //virtual bool OnMouseHover( UINT nFlags, QPoint& point );
    virtual bool OnMouseMove( UINT flags, QPoint & point );

protected:
    //signals
    virtual void OnTabChange() {}

protected:
    void    DrawTabs( QGraphics * pdc, int iSel = -1 , bool xhover = false );
    void    RedrawTabs( int sel = -1, bool xhover = false );


    void	AdjustRect( BOOL flag, QRect & rect );
    void    RecalcLayout();
    bool    HitTest( const QPoint & pt, int & nItem, bool & onclose  );
    QRect   GetCloseButton( int n );

public:
    ///colors
    void	SetBkColor( QCOLOR c );
    void	SetStyle( UINT style );

    ///insert after current tab
    bool    InsertTab( QPanel * pChild, QString pMsg = _T( "" ),    UINT id  = 0 );
    bool	AddTab( QPanel * pChild, QString lpMsg = _T( "" ),   UINT id  = 0 );

    void    RemoveTab( int nrTab );
    void	RemoveTab( QPanel  * p );
    void    RemoveAllTabs( );
    void	RemoveTabByID( int unicid );

    void    SetTabCaptionByID( const QString str , int id );
    void	SetCurrentTabCaption( const QString str );
    void	SetCurrentTabID( int id );
    void    SetActiveTabByID( int unicid );
    void	SetActiveTab( int tab );
    int		GetCurrentTab();
    int		GetTabCount();
    UINT    GetActiveTabID();

    void    MoveNextTab( bool next = true );

    QWindow * GetCurrentWindow();
    QWindow * GetChildWindow( int tab );

    bool	Find( QPanel * p );
    bool    FindTabByID( int id );
    void    DrawXbutton( QGraphics &  , QRect & r , bool red = false );

};



}
}//micro